// setTimeout模拟setInterval
// 可以清楚定时器
function mySetInterval(fn, t) {
  let timer = null
  function interval() {
    fn()
    timer = setTimeout(interval, t)
  }
  interval()
  return {
    clear: function () {
      clearTimeout(timer)
    }
  }
}

// let interval = mySetInterval(() => {
//   console.log('hello');
// }, 500)

// setTimeout(() => {
//   interval.clear()
// }, 2000)


// setInterval 模拟 setTimeout

function mySetTimeout(fn, delay) {
  let timer = setInterval(()=>{
    clearInterval(timer)
    fn()
  },delay)
}
mySetTimeout(()=>{
  console.log(123);
},2000)